<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var numRescueBoats = (people, limit) => {
      if (people.sort((a, b) => a - b)[0] >= limit) return people.length
      let res = 0
      for (let i = 0, j = people.length - 1; i <= j; people[i] + people[j] <= limit && i++, j--) {
        res++
      }
      return res
    };
    console.log(numRescueBoats(people = [1, 2], limit = 3))
  </script>
</body>

</html>